package com.aigou.admin.service.impl;

import com.aigou.admin.dao.SalesDao;
import com.aigou.admin.dao.UserDao;
import com.aigou.admin.dao.impl.SalesDaoImpl;
import com.aigou.admin.dao.impl.UserDaoImpl;
import com.aigou.admin.entity.PageEntity;
import com.aigou.admin.entity.Sales;
import com.aigou.admin.entity.Shop_cart_product;
import com.aigou.admin.service.SalesService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: May
 * @Date: 2024/12/3 16:38
 * @Version: 1.0
 */
@Service
@AllArgsConstructor
public class SalesServiceImpl implements SalesService {

    private final SalesDao salesDao;

    @Override
    public List<Sales> findAll() {
        return salesDao.selectAll();
    }

    @Override
    public Sales findById(String id) {
        return salesDao.selectById(id);
    }

    @Override
    public Boolean save(Sales sales) {
        return salesDao.insert(sales);
    }

    @Override
    public Boolean update(Sales sales) {
        return salesDao.update(sales);
    }

    @Override
    public Boolean remove(String id) {
        return salesDao.delete(id);
    }

    @Override
    public PageEntity<Sales> findUserPage(Integer current, Integer pageSize) {
        //查询用户总数 count(*)
        int total = salesDao.selectUserCount();
        //分页查询用户数据 limit
        List<Sales> sales = salesDao.selectUserLimit((current-1) * pageSize,pageSize);
        //发送数据给前端
        PageEntity<Sales> pageEntity = new PageEntity<>();
        pageEntity.setCurrent(current);
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setRecords(sales);
        return pageEntity;
    }

    @Override
    public List<Sales> findByNameContaining(String id) {
        return salesDao.findByNameContaining(id);
    }
}
